#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
#define x first
#define y second
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 5010;
pii p[N];
int n;
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y;
    sort(p, p + n);
    ll maxl = 0, maxno = 0;
    ll l = p[0].x, r = p[0].y;
    for (int i = 0; i < n; i++)
    {
        if (p[i].x <= r) r = max(r, (ll)p[i].y);
        else
        {
            maxno = max(maxno, (ll)p[i].x - r);
            l = p[i].x;
            r = p[i].y;
        }
        maxl = max(maxl, r - l);
    }
    cout << maxl << " " << maxno << endl;
    return 0;
}